<?php

class Damages_Methods_Data_CarDamageList {

  const FIELD_CODE_ID = 'id';
  const FIELD_CODE_CREATED = 'created';
  const FIELD_CODE_VIN = 'vin';
  const FIELD_CODE_MODEL_NAME = 'model_name';
  const FIELD_CODE_DEALER_NUMBER = 'dealer_no';
  const FIELD_CODE_DEALER_NAME = 'dealer';
  const FIELD_CODE_DAMAGE_TYPE = 'dam_type';
  const FIELD_CODE_PERPETRATOR = 'perpetrat';
  const FIELD_CODE_DAMAGE_DATE = 'dam_date';
  const FIELD_CODE_COMMISION = 'commision';
  const FIELD_CODE_LS = 'ls_id';
  const FIELD_CODE_BRAND = 'brand_id';
  const FIELD_CODE_TRANSPORT_TYPE = 'trans_type';
  const FIELD_CODE_STATUS = 'status_id';
  const FIELD_CODE_INVOICE = 'invoice_no';
  const FIELD_CODE_DEALER_REPORT_DATE = 'dealer_rep';
  const FIELD_CODE_MODIFIED = 'modified';

  public function __construct(DamagesCarDamages $obj) {
    foreach (Damages_Auth::getInstance()->getFieldsPermissions() as $fieldPermission) {
      $cd = $fieldPermission->getListFields()->getCode();
      switch ($cd) {
        case self::FIELD_CODE_ID:
          $this->$cd = $obj->getId();
          break;
        case self::FIELD_CODE_CREATED:
          $this->$cd = $obj->getCreated();
          break;
        case self::FIELD_CODE_VIN:
          $this->$cd = $obj->getCarData()->getVin();
          break;
        case self::FIELD_CODE_MODEL_NAME:
          $this->$cd = $obj->getCarData()->getName();
          break;
        case self::FIELD_CODE_DEALER_NUMBER:
          if ($obj->getCarData()->getDealersRelatedByDealerId())
            $this->$cd = $obj->getCarData()->getDealersRelatedByDealerId()->getNumber();
          break;
        case self::FIELD_CODE_DEALER_NAME:
          if ($obj->getCarData()->getDealersRelatedByDealerId())
            $this->$cd = $obj->getCarData()->getDealersRelatedByDealerId()->getName();
          break;
        case self::FIELD_CODE_DAMAGE_TYPE:
          if (in_array(Damages_Auth::getInstance()->getUser()->getPermissions()->getCode(), array(Damages_Auth::PERMISSION_ADMIN, Damages_Auth::PERMISSION_LS)) && $obj->getRelatedCarDamage())
            $this->$cd = $obj->getCarDamagesRelatedByRelatedCarDamage()->getProcessTypes()->getName();
          else
            $this->$cd = $obj->getProcessTypes()->getName();
          break;
        case self::FIELD_CODE_PERPETRATOR:
          $this->$cd = $obj->getDictPerpetrators()->getName();
          break;
        case self::FIELD_CODE_DAMAGE_DATE:
          $this->$cd = $obj->getDamageDate();
          break;
        case self::FIELD_CODE_COMMISION:
          $this->$cd = $obj->getCarData()->getComissionNo();
          break;
        case self::FIELD_CODE_LS:
          $this->$cd = $obj->getUsersRelatedByLsId() ?
                  $obj->getUsersRelatedByLsId()->getFirstName() . ' ' . $obj->getUsersRelatedByLsId()->getLastName() :
                  null;
          break;
        case self::FIELD_CODE_BRAND:
          $this->$cd = $obj->getCarData()->getDictBrands()->getName();
          break;
        case self::FIELD_CODE_TRANSPORT_TYPE:
          $this->$cd = $obj->getDictPerpetrators()->getTransportType();
          break;
        case self::FIELD_CODE_STATUS:
          if (in_array(Damages_Auth::getInstance()->getUser()->getPermissions()->getCode(), array(Damages_Auth::PERMISSION_SD)))
            $this->$cd = $obj->getDictStatuses()->getDealerName() ? $obj->getDictStatuses()->getDealerName() : $obj->getDictStatuses()->getName();
          else
            $this->$cd = $obj->getDictStatuses()->getName();
          break;
        case self::FIELD_CODE_INVOICE:
          $this->$cd = !$obj->getInvoicess()->isEmpty() ?
                  $obj->getInvoicess()->getFirst()->getNumber() :
                  null;
          break;
        case self::FIELD_CODE_DEALER_REPORT_DATE:
          $this->$cd = $obj->getDealerReportDate();
          break;
        case self::FIELD_CODE_MODIFIED:
          $this->$cd = $obj->getModified();
          break;
        default:
          break;
      }
    }
  }

}